<?php
namespace logic\sys\images;
class ImageAlbum extends \logic\Base{
    
    
    private $tagList = [
        'cases'     => '案例图片',
        'news'      => '新闻图片',
        'default'   => '其他图片',
        'editor'    => '编辑器图片',
        'logo'      => 'logo图片',
        'advert'    => '广告图片',
    ];
    
    /**
     * 根据类型 读取一个相册的ID 
     * 存在则返回 不存在则创建新的相册
     */
    public function getAlbumId($param){        
        $check = [            
            'utype'     => ['check'=>'must','reg'=>[1,2,3,4]],
            'uid'       => ['check'=>'must','reg'=>'int'],
            'tag'       => ['check'=>'must'],   
        ];
        $data = pVerify($check,$param);
        $info =  D('ImageAlbum','sysImages')->find($data);
        if( $info )  return $info['id'];
        
        $data['name'] = $this->tagList[$data['tag']];
        return D('ImageAlbum','sysImages')->add($data);
    }
    
    /**
     * 读取相册列表
     */
    public function getAlbumList($param){
        return D('ImageAlbum','sysImages')->getList($param);
    }
    
    /**
     * 站点读取公共相册
     */
    public function getSitePublicAlbum(){
        $result =  cache('logic_sys_imgpublic');
        if( !$result ){
            $where = [
                'utype' => 1,
                'tag'   => 'public',
                'status'=> 1,
            ];
            $result = D('ImageAlbum','sysImages')->getList($where);
            cache('logic_sys_imgpublic',$result,86400);
        }
        return $result;        
    }
    
}